package com.xm.runtimetask;

import androidx.appcompat.app.AppCompatActivity;
import androidx.test.uiautomator.UiDevice;

import android.app.KeyguardManager;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.xm.runtimetask.util.CmdUtil;
import com.xm.runtimetask.util.TimeTaskUtil;

public class MainActivity extends AppCompatActivity {
    Button everyDayStartBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        everyDayStartBtn = findViewById(R.id.startEveryDayBtn);
        if (TimeTaskUtil.getInstance(getApplication()).isStartEveryDayTask()){
            everyDayStartBtn.setText("开始每天刷(已设置)");
        }else{
            everyDayStartBtn.setText("开始每天刷(未设置)");
        }

}

    public void onBtnClick(View view) {
        if (view.getId() == R.id.startBtn1) {
            int runTotalSecodes = 60*60*1;//2小时
            CmdUtil.execHomeKeyCmd();
            TimeTaskUtil.getInstance(getApplication()).startTimeTask(runTotalSecodes);
            Toast.makeText(this, "启动了1", Toast.LENGTH_SHORT).show();
        }else if (view.getId() == R.id.startBtn2) {
            int runTotalSecodes = 60*60*2;//2小时
            CmdUtil.execHomeKeyCmd();
            TimeTaskUtil.getInstance(getApplication()).startTimeTask(runTotalSecodes);
            Toast.makeText(this, "启动了2", Toast.LENGTH_SHORT).show();
        }else if (view.getId() == R.id.startBtn6) {
            int runTotalSecodes = 60*60*6;
            CmdUtil.execHomeKeyCmd();
            TimeTaskUtil.getInstance(getApplication()).startTimeTask(runTotalSecodes);
            Toast.makeText(this, "启动6", Toast.LENGTH_SHORT).show();
        }else if (view.getId() == R.id.startBtn8) {
            int runTotalSecodes = 60*60*8;
            CmdUtil.execHomeKeyCmd();
            TimeTaskUtil.getInstance(getApplication()).startTimeTask(runTotalSecodes);
            Toast.makeText(this, "启动8", Toast.LENGTH_SHORT).show();
        }else if (view.getId() == R.id.stopBtn) {
            TimeTaskUtil.getInstance(getApplication()).stopRunTimeTask();
            Toast.makeText(this, "停止任务", Toast.LENGTH_SHORT).show();
        }
        else if (view.getId() == R.id.startEveryDayBtn) {
            TimeTaskUtil.getInstance(getApplication()).startTimeTaskEveryDayAlarm();
            Toast.makeText(this, "开启每天自动刷", Toast.LENGTH_SHORT).show();
            everyDayStartBtn.setText("开始每天刷(已设置)");
        }else if (view.getId() == R.id.stopEveryDayBtn) {
            TimeTaskUtil.getInstance(getApplication()).cancelTimeTaskEveryDayAlarm();
            Toast.makeText(this, "取消每天自动刷", Toast.LENGTH_SHORT).show();
            everyDayStartBtn.setText("开始每天刷(未设置)");
        }
    }
}
